<!DOCTYPE html>
<html>
	<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>SB Admin - Bootstrap Admin Template</title>

    <!-- Bootstrap Core CSS -->
    <link href="__PUBLIC__/home/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <!--<link href="_PUBLIC__/font/css/font-awesome.min.css" rel="stylesheet" type="text/css">-->

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
	
</head>
	<body>
		<!--<div class="container-fluid">-->
        <!-- Page Heading -->
	        <div class="row">
				<div class="col-md-12">
					<ol class="breadcrumb">
						<li class="active">
							<i class="fa fa-fw fa-edit"></i>
							命令管理
						</li>
					</ol>
				</div>
			</div>
			<div class="row">
				<ul class="nav nav-tabs" role="tablist">
				    <li role="presentation" class="active"><a href="#message" aria-controls="home" role="tab" data-toggle="tab">基本信息</a></li>
			 	</ul>
			 	<div class="tab-content col-xs-12">
					<div role="tabpanel" class="tab-pane active" id="message">
						<div class="row">
							<div class="col-sm-10">
								<form id="zyn-form-add" class="form-horizontal">
									<div class="form-group">
										<label for="lc-input-condition_name" class="control-label col-sm-2">条件名称</label>
										<div class="col-sm-3">
											<input id="lc-input-condition_name" class="form-control" type="text" name="condition_name" value=""/>
										</div>
										<div class="col-sm-3">
											<p class="lc-p-validate-result p-no-margin" attr-validate = "condition_name">*命令名</p>
										</div>
									</div>
									<div class="form-group">
										<label for="lc-input-condition_value" class="control-label col-sm-2">条件指令</label>
										<div class="col-sm-3">
											<input id="lc-input-condition_value" class="form-control" type="text" name="condition_value" value=""/>
										</div>
										<div class="col-sm-3">
											<p class="lc-p-validate-result p-no-margin" attr-validate = "condition_value">*命令名</p>
										</div>
									</div>
									<div class="form-group">
										<label for="lc-input-compare_id" class="control-label col-sm-2">比较类型</label>
										<div class="col-sm-3">
											<select class="p-no-margin form-control" value="比较类型" id="lc-select-compare_id">
												<volist name="compare" id="com">
													<option value="{$com.compare_id}">{$com.compare_name}</option>
												</volist>
											</select>
										</div>
										<div class="col-sm-3">
											<p class="lc-p-validate-result p-no-margin" attr-validate = "condition_value">*比较类型</p>
										</div>
									</div>
									<div class="form-group">
										<label for="lc-input-unit" class="control-label col-sm-2">单位</label>
										<div class="col-sm-3">
											<input id="lc-input-unit" class="form-control" type="text" name="unit" value=""/>
										</div>
										<div class="col-sm-3">
											<p class="lc-p-validate-result p-no-margin" attr-validate = "unit">*命令名</p>
										</div>
									</div>
								</form>
							</div>	
						</div>
					</div>
 				<div class="col-xs-10 col-xs-offset-2">
 					<button class="btn btn-primary" id="xx-btn-save">提交保存</button>
 					<button class="btn btn-primary" id="xx-btn-return">返回上一页</button>
 				</div>
			</div>
		</div>
		
	</body>
	<script src="__PUBLIC__/home/js/jquery.min.js"></script>
    <script src="__PUBLIC__/home/js/bootstrap.min.js"></script>
    <script src=""></script>
	<script>
    $(document).ready(function() {
    	var temp = localStorage.getItem('admin');
    	var tempRole_name = JSON.parse(temp).role_name;
    	if(tempRole_name == '超级管理员'){
    		$("#xx-select").append("<option>管理员</option><option>工作人员</option>");
    	}else if(tempRole_name == '管理员'){
    		$("#xx-select").append("<option>工作人员</option>");
    	}
//  	console.log(JSON.parse(temp).role_name);
    	$('#zyn-input-uploader').uploadify({
			'swf':'__ROOT__/Public/js/vendor/uploadify/uploadify.swf',
			'uploader':'__URL__/ajaxUploadImage',
			'buttonText':'上传图片',
			'fileTypeExts':'*.gif;*.png;*.jpg;*.jpeg;',
			'fileTypeDecs':'Image File',
			'fileObjName':'file',
			'onUploadSuccess':function(file,data,response){
				if(response){
					var res = JSON.parse(data);
					console.log(res.data.thumb_path);
					$('#zyn-image-show-thumb').attr('src',res.data.thumb_path).show();
					$('#zyn-input-image-path').attr('value',res.data.thumb_path);
				}
			},
		});
		
    });
    $("#xx-btn-return").click(function(){
    	location.href = "{:U('Condition/index')}";
    });
    $("#xx-btn-save").click(function(){
		$.ajax({
			type:"post",
			url:"{:U('Condition/insertConditionInfo')}",
			data:{
				'condition_name':$("#lc-input-condition_name").val(),
				'condition_value':$("#lc-input-condition_value").val(),
				'unit':$("#lc-input-unit").val(),
				'compare_id':$("#lc-select-compare_id").val(),
			},
			dataType:'json',
			success:function(result){
				//链接服务器其成功
				if(result.status == 1){
					//成功
					return location.href = "{:U('Condition/index')}";
				}else if (result.status == VALIDATE_ERROR){
					//表单验证出错
					var errors = result.msg;
					$('.zyn-p-validate-result').each(function(){
						var errorMsg = errors[$(this).attr('attr-validate')];
						$(this).html(errorMsg != undefined ? '*'+errorMsg : '').css({color:'red'});
					});
				}else{
					return Dialog.error(result.msg);
				}
				
			},
			
		});
    });
    </script>
</html>
